<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<head>
    <title>新增子账号</title>
    <%@include file="/WEB-INF/pages/common/taglib.jsp" %>
    <%@include file="/WEB-INF/pages/common/common.jsp" %>
    <style>
        .table_add input {
            border: 1px solid lightgray !important;
            height: 20px !important;;
            color: #373737;
            font-size: 12px;
            line-height: 20px;
            width: 180px !important;
        }

        .title {
            background-color: #e9f5ff;
            width: 30%;
            padding-right: 10px;
            text-align: right;
        }
    </style>
    <script>
        $.validator.setDefaults({
            submitHandler: function () {
                alert("提交事件!");
            }
        });
        $().ready(function () {
            // 在键盘按下并释放及提交后验证提交表单
            $("#signupForm").validate({
                rules: {
                    userName: {
                        required: true, minlength: 2
                    }, password: {
                        required: true, minlength: 5
                    }, verifyPassword: {
                        required: true, minlength: 5, equalTo: "#password"
                    }, mail: {
                        required: true, email: true
                    }, phone: {
                        required: true, rangelength: [11, 11], checkMobile: true
                    }
                }, messages: {
                    username: {
                        required: "请输入用户名", minlength: "用户名必需由两个字母组成"
                    }, password: {
                        required: "请输入密码", minlength: "密码长度不能小于 5 个字母"
                    }, verifyPassword: {
                        required: "请输入密码", minlength: "密码长度不能小于 5 个字母", equalTo: "两次密码输入不一致"
                    }, phone: {
                        required: "请输入手机号", rangelength: "请输入11位手机号"
                    }, mail: {
                        required: "请输入邮箱地址", email: "请输入正确的邮箱地址"
                    }
                }, submitHandler: function (form) {
                    addChildUser();
                }
            });
        });
        jQuery.validator.addMethod("checkUsername", function (value) {
            var reg = /^[a-zA-Z][a-zA-Z0-9_]*$/;
            if (reg.test(value)) {
                return true;
            }
            return false;
        }, "请输入字母开头的字母数字下划线组合");
        jQuery.validator.addMethod("checkMobile", function (value) {
            var reg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
            if (reg.test(value)) {
                return true;
            }
            return false;
        }, "请输入有效的手机号码");
        function isNotNull(param) {
            if ($.trim(param) != "" && param != null) {
                return true;
            } else {
                return false;
            }
        }
        //将表单数据转为json
        function form2Json(id) {
            var arr = $("#" + id).serializeArray();
            var jsonStr = "";
            var json = "";
            for (var i = 0; i < arr.length; i++) {
                if (isNotNull(arr[i].value)) {
                    jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
                }
            }
            if (isNotNull(jsonStr)) {
                jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
                jsonStr = "{" + jsonStr + "}";
                json = JSON.parse(jsonStr);
            }
            return json;
        }
        function addChildUser() {
            $.post("${basePath}/reg/addChildUsr?r" + Math.random(), form2Json("signupForm"), function (data) {
                if (data) {
                    if (data == "success") {
                        var index = parent.layer.getFrameIndex(window.name); //获取当前窗体索引
                        parent.location.reload();
                        parent.layer.close(index); //执行关闭
                    } else {
                        layer.alert(data, {icon: 5});
                    }
                }
            });
        }
    </script>
</head>
<body>
<form class="cmxform" id="signupForm" method="get">
    <table class="table_detail table_add">
        <tr>
            <td class="title"><em>*</em>用户名:</td>
            <input type="hidden" name="parentId" id="parentId" value="${parentId}"/>
            <td><input type="text" name="userName" id="userName"></td>
        </tr>
        <tr>
            <td class="title"><em>*</em>密码:</td>
            <td><input type="password" name="password" id="password"></td>
        </tr>
        <tr>
            <td class="title"><em>*</em>确认密码:</td>
            <td><input type="password" name="verifyPassword" id="verifyPassword"></td>
        </tr>
        <tr>
            <td class="title"><em>*</em>邮箱:</td>
            <td><input type="text" name="mail" id="mail"></td>
        </tr>
        <tr>
            <td class="title"><em>*</em>手机号:</td>
            <td><input type="text" name="phone" id="phone"></td>
        </tr>
        <tr class="tr_button">
            <td colspan="2">
                <input type="submit" style="width: 60px !important;" value="提交">
            </td>
        </tr>
    </table>
</form>

</body>
</html>
